<template>
	<view>
		<view class="big-box">
			<view class="top-box">
				<image style="width: 200rpx;height: 200rpx;" src="https://syxiyi.oss-cn-shenzhen.aliyuncs.com/frontend/img/a-logo.png"></image>
			</view>
			<view style="width: 690rpx;text-align: left;">
				<view style="font-size: 34rpx;padding-top: 20rpx;">申请获取以下权限</view>
				<view style="font-size: 30rpx;padding-top: 20rpx;color: #A8A8A8;">
					获得你的公开信息（昵称、头像等）
				</view>
			</view>
			<button class="sys_btn" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="getPhoneNumber">绑定手机号</button>


		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				iv: '',
				encryptedData: ''
			}
		},
		methods: {
			// #ifdef MP-WEIXIN
			getPhoneNumber(e) {
				console.log(e)
				console.log(e.detail.errMsg)
				console.log(e.detail.iv)
				console.log(e.detail.encryptedData)
				this.logins(e)
			},
			//#endif
			logins(e) {
				let iv = e.detail.iv
				// let encryptedData = encodeURIComponent(e.detail.encryptedData)
				let encryptedData = e.detail.encryptedData
				uni.login({
					provider: 'weixin',
					success: (loginRes) => {
						let js_code = loginRes.code;
						this.$ajaxRequest.post(this.baseUrl + 'user/wxPhone', {
							iv: iv,
							encryptedData: encryptedData
						}).then((res) => {
							console.log(res)
							if(res.data.code == 200){
								uni.setStorageSync('mobile', res.data.data.mobile);
								uni.switchTab({
									url:'../../index/index'
								})
							}else{
								
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.top-box {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		padding-bottom: 60rpx;
		border-bottom: 1rpx solid rgba(48, 48, 48, .2);
	}

	.buts {
		color: white;
		border-radius: 10rpx;
		padding: 10rpx 30rpx 10rpx 30rpx;
		background: #39B54A;
		margin-top: 30rpx;
		display: flex;
		align-items: center;
	}

	.but {
		font-size: 30rpx;
	}

	.sys_btn {
		width: 690rpx;
		border-radius: 60rpx;
		color: white;
		background:linear-gradient(-17deg,rgba(255,114,59,1),rgba(255,147,67,1));
		margin-top: 60rpx;
	}

	.big-box {
		height: 600rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}
</style>
